<?php

/**
 * 性别数转性别名
 *
 * @param int $sexnumber
 *
 * @return string
 */
function sexnumberTOsexname( $sexnumber ) {
	switch ( $sexnumber ) {
		case '0':
			return '保密';
		case '1':
			return '男';
		case '2':
			return '女';
		default:
			return '未知';
	}
}

/**
 * 数据库生日转文字
 *
 * @param int $bitrhdayNnmber
 *
 * @return string
 */
function birthdaynumberTObirthdaytext( $bitrhdayNnmber ) {
	if ( $bitrhdayNnmber == null ) {
		return '未知';
	}

	return date( "Y年m月d日", $bitrhdayNnmber );
}

function adminsetting() {
	exit();
}

function ip() {
	//strcasecmp 比较两个字符，不区分大小写。返回0，>0，<0。
	if ( getenv( 'HTTP_CLIENT_IP' ) && strcasecmp( getenv( 'HTTP_CLIENT_IP' ), 'unknown' ) ) {
		$ip = getenv( 'HTTP_CLIENT_IP' );
	} elseif ( getenv( 'HTTP_X_FORWARDED_FOR' ) && strcasecmp( getenv( 'HTTP_X_FORWARDED_FOR' ), 'unknown' ) ) {
		$ip = getenv( 'HTTP_X_FORWARDED_FOR' );
	} elseif ( getenv( 'REMOTE_ADDR' ) && strcasecmp( getenv( 'REMOTE_ADDR' ), 'unknown' ) ) {
		$ip = getenv( 'REMOTE_ADDR' );
	} elseif ( isset( $_SERVER['REMOTE_ADDR'] ) && $_SERVER['REMOTE_ADDR'] && strcasecmp( $_SERVER['REMOTE_ADDR'], 'unknown' ) ) {
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	$res = preg_match( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';

	return $res;
	//dump(phpinfo());//所有PHP配置信息
}

/**
 * 论坛管理
 */
function adminArea() {
	echo '<h4>管理论坛区：</h4>';

	if ( isset( $_GET['type'] ) ) {
		if ( $_GET['type'] == 'area' ) {
			if ( isset( $_GET['delete'] ) ) {
				sql_delArea( $_GET['delete'] );
			}
			if ( isset( $_GET['id'] ) ) {
				if ( isset( $_GET['deleteforum'] ) ) {
					sql_delForum( $_GET['id'], $_GET['deleteforum'] );
				} elseif ( isset( $_GET['forumid'] ) ) {
					if ( isset( $_GET['deletetopic'] ) ) {
						sql_delTopic( $_GET['deletetopic'], $_GET['forumid'], $_GET['id'] );
					}
					editForum( $_GET['id'], $_GET['forumid'] );
				} else {
					$setAreaId = $_GET['id'];
					editArea( $setAreaId );
				}
			} else {
				Area();
			}
		} else {
			Area();
		}
	} else {
		Area();
	}
}

function Area() {
	echo '现有论坛区：<br />';
	if ( ! isset( $_GET['areap'] ) ) {
		$areap = 1;
	} else {
		$areap = $_GET['areap'] ? $_GET['areap'] : 1;
	}
	$offset         = ( $areap - 1 ) * 5;
	$searchAreaAsc  = search_bbs_area_asc( $offset, 5 );
	$searchAreaDesc = search_bbs_area_desc();
	echo '<table border="1" width="50%" cellpadding="0" cellspacing="0">';
	echo '<th>论坛顺序</th><th>论坛ID</th><th>论坛名</th><th>待审核</th>';
	$i = 1;
	while ( ( $array = mysqli_fetch_array( $searchAreaAsc ) ) != false ) {
		echo '<tr>';
		echo '<td>' . $array['area_order'] . '</td>';
		echo '<td>' . $array['area_id'] . '</td>';
		echo '<td><a href="admin.php?type=area&id=' . $array['area_id'] . '">' . $array['area_title'] . '</a>';
		echo '&nbsp;&nbsp;&nbsp;&nbsp;';
		?>
        <a href="admin.php?type=area&delete=<?= $array['area_id'] ?>"
           onClick="return confirm('确定删除?');">删除</a>
		<?php
		echo '</td>';
		echo '<td></td>';
		echo '</tr>';
		$i ++;
	}
	echo '</table>';
	echo '新增论坛区：<br />';
	echo '<input type="text" id="addArea"/>';
	echo '<select id="selectOrder">';
	$neworder = mysqli_fetch_array( $searchAreaDesc );
	echo '<option value="' . ( $neworder['area_order'] + 1 ) . '">' . ( $neworder['area_order'] + 1 ) . '</option>';
	echo '<option value="' . $neworder['area_order'] . '">' . $neworder['area_order'] . '</option>';
	while ( ( $array = mysqli_fetch_array( $searchAreaDesc ) ) != false ) {
		echo '<option value="' . $array['area_order'] . '">' . $array['area_order'] . '</option>';
	}
	echo '</select>';
	echo '<input type="button" onclick="ajaxpost_addArea()" value="增加"/><br />';
}

/**
 * 论坛内及板块管理
 *
 * @param int $areaid
 */
function editArea( $areaid ) {
	$area_array = sql_area( $areaid );
	?>
    <h5>编辑论坛：</h5>
    论坛名：
    <input id="editAreaName" type="text"
           value="<?= $area_array['area_title'] ?>"/>
    <input type="hidden" id="areaid" value="<?= $_GET['id'] ?>"/>
    <input type="button" onClick="editAreaTitle()" value="修改">
    <h5>论坛板块：</h5>
	<?php
	echo '现有板块：<br />';
	if ( ! isset( $_GET['forump'] ) ) {
		$areap = 1;
	} else {
		$areap = $_GET['forump'] ? $_GET['forump'] : 1;
	}
	$offset          = ( $areap - 1 ) * 5;
	$searchForumsAsc = search_bbs_forums_asc( $_GET['id'], $offset, 100 );
	echo '<table border="1" width="50%" cellpadding="0" cellspacing="0">';
	echo '<th>板块ID</th><th>板块名</th><th>主题数</th><th>待审核</th>';
	while ( ( $array = mysqli_fetch_array( $searchForumsAsc ) ) != false ) {
		echo '<tr>';
		echo '<td>' . $array['forum_id'] . '</td>';
		echo '<td><a href="admin.php?type=area&id=' . $_GET['id'] . '&forumid=' . $array['forum_id'] . '">' . $array['forum_name'] . '</a>';
		echo '&nbsp;&nbsp;&nbsp;&nbsp;';
		?>
        <a
                href="admin.php?type=area&id=<?= $_GET['id'] ?>&deleteforum=<?= $array['forum_id'] ?>"
                onClick="return confirm('确定删除?');">删除</a>
		<?php
		echo '</td><td>' . sql_count_forumid_topic( $array['forum_id'] ) . '</td>';
		$waitcs = sql_count_forumid_waittopic( $array['forum_id'] );
		echo '<td>' . $waitcs . '</td>';
		echo '</tr>';
	}
	echo '</table>';
	echo '新增版块：<br />';
	echo '<input type="text" id="addForum"/>';
	echo '<input type="hidden" id="addForumAreaId" value="' . $_GET['id'] . '"/><br />';
	echo '板块说明：';
	?>
    <!-- 加载编辑器的容器 -->
    <script id="container" name="content" type="text/plain"></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="utf8-php/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="utf8-php/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container');
    </script>
	<?php
	echo '<input type="button" onclick="ajaxpost_addForum()" value="增加"/><br />';
	echo '<a href="admin.php?type=area">返回</a>';
}

/**
 * 主题管理
 *
 * @param int $areaid
 * @param int $forumid
 */
function editForum( $areaid, $forumid ) {
	$area_array = sql_area( $areaid );
	?>
    <h5>编辑板块：</h5>
    论坛名：<a href="admin.php?type=area&id=<?= $_GET['id'] ?>"><?= $area_array['area_title'] ?></a>
    <h5>论坛板块：</h5>
	<?php
	$forums_array = sql_forumid_forums( $forumid );
	?>
    板块名：
    <input id="editForumName" type="text"
           value="<?= $forums_array['forum_name'] ?>"/>
    <input type="hidden" id="forumid" value="<?= $_GET['forumid'] ?>"/>
    <!-- 加载编辑器的容器 -->
    <script id="container" name="content" type="text/plain"><?= $forums_array['forum_desc'] ?></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="utf8-php/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="utf8-php/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container');
    </script>
    <h5>发帖等级：</h5>
    <input id="auth_post" type="text" value="<?= $forums_array['auth_post'] ?>"/>
    <h5>编辑权限：</h5>
	<?php if ( $_SESSION['rank'] == 10 ) { ?>
        <input type="text" id="auth_edit" value="<?= $forums_array['auth_edit'] ?>"/>
	<?php } else {
		?>
        <input type="text" id="auth_edit" value="<?= $forums_array['auth_edit'] ?>" disabled="disabled"/>
		<?php
	} ?>
    <br/><br/>
    <input type="button" onClick="editForum()" value="修改">
    <h5><a name="topic">主题：</a></h5>
    现有主题：
    <br/>
    筛选：
    <select id="filter_status" onchange="change_filter_status(<?= $_GET['id'] ?>,<?= $_GET['forumid'] ?>)">
		<?php
		if ( isset( $_GET['filter'] ) ) {
			$filter = $_GET['filter'];
			switch ( $filter ) {
				case "0":
					{
						?>
                        <option value="0" selected="selected">所有</option>
                        <option value="1">隐藏</option>
                        <option value="2">正常</option>
                        <option value="3">待审核</option>
						<?php
						break;
					}
				case "1":
					{
						?>
                        <option value="0">所有</option>
                        <option value="1" selected="selected">隐藏</option>
                        <option value="2">正常</option>
                        <option value="3">待审核</option>
						<?php
						break;
					}
				case "2":
					{
						?>
                        <option value="0">所有</option>
                        <option value="1">隐藏</option>
                        <option value="2" selected="selected">正常</option>
                        <option value="3">待审核</option>
						<?php
						break;
					}
				case "3":
					{
						?>
                        <option value="0">所有</option>
                        <option value="1">隐藏</option>
                        <option value="2">正常</option>
                        <option value="3" selected="selected">待审核</option>
						<?php
						break;
					}
				default:
					?>
                    <option value="0">所有</option>
                    <option value="1">隐藏</option>
                    <option value="2">正常</option>
                    <option value="3">待审核</option>
					<?php
					break;
			}
		} else {
			$filter = 0;
			?>
            <option value="0">所有</option>
            <option value="1">隐藏</option>
            <option value="2">正常</option>
            <option value="3">待审核</option>
			<?php
		}
		?>
    </select>
	<?php
	$waitcs = sql_count_forumid_waittopic( $_GET['forumid'] );
	echo "待审核：<u>" . $waitcs . "</u> 贴";
	?>
    <br/>
	<?php


	if ( ! isset( $_GET['forump'] ) ) {
		$areap = 1;
	} else {
		$areap = $_GET['forump'] ? $_GET['forump'] : 1;
	}
	$offset = ( $areap - 1 ) * 10;

	//------------------------------------------------------------------------------------------------------------------------
	$getforumid   = $_GET['forumid'];
	$count_result = sql_forumid_nomal_fliter_page( $getforumid, $filter );
	$count_array  = mysqli_fetch_array( $count_result );
	$pagenum      = ceil( $count_array['COUNT(*)'] / 10 );
	echo '<p style="text-align: right">';
	if ( $areap > 1 ) {
		echo '<a href="admin.php?type=area&id=' . $_GET['id'] . '&forumid=' . $getforumid . '&forump=' . ( $areap - 1 ) . '#topic"><<上一页</a>&nbsp;&nbsp;';
	}
	echo '共 ', $count_array['COUNT(*)'], ' 条';
	if ( $pagenum > 1 ) {
		for ( $i = 1; $i <= $pagenum; $i ++ ) {
			if ( $i == $areap ) {
				echo '&nbsp;[', $i, ']';
			} else {
				echo '&nbsp;<a href="admin.php?type=area&id=' . $_GET['id'] . '&forumid=' . $getforumid . '&forump=' . $i . '#topic">' . $i . '</a>';
			}
		}
	}
	if ( $areap < $pagenum ) {
		echo '&nbsp;&nbsp;<a href="admin.php?type=area&id=' . $_GET['id'] . '&forumid=' . $getforumid . '&forump=' . ( $areap + 1 ) . '#topic">下一页>></a>';
	}
	echo '</p>';
	//------------------------------------------------------------------------------------------------------------------------

	$searchForumsAsc = sql_forumid_topics( $_GET['forumid'], $filter, $offset, 10 );
	echo '<table border="1" width="80%" cellpadding="0" cellspacing="0">';
	echo '<tr><th width="5%">主题ID</th><th width="20%">主题名</th><th width="5%">主题回复</th><th width="10%">主题状态</th><th width="5%">编辑主题</th></tr>';
	while ( ( $array = mysqli_fetch_array( $searchForumsAsc ) ) != false ) {
		echo '<tr>';
		echo '<td>' . $array['topic_id'] . '</td>';
		$type_val = sql_topicid_type( $array['topic_id'] );
		if ( $type_val == 1 ) {
			$type_url = "<a href='forums.php?forumid=" . $_GET['forumid'] . "&type=1&p=1'><span style=\"color: #FF0000\">求助</span></a>";
		} elseif ( $type_val == 2 ) {
			$type_url = "<a href='forums.php?forumid=" . $_GET['forumid'] . "&type=2&p=1'><span style=\"color: #00CC00\">已解决</span></a>";
		}

		echo '<td>';
		if ( $array['topic_top'] == 1 ) {
			echo '[<span style="color:#FF6600">置顶</span>]';
		}
		echo '[' . $type_url . ']<a href="topic.php?topicid=' . $array['topic_id'] . '&p=1">' . $array['topic_title'] . '</a>';
		?>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <a href="admin.php?type=area&id=<?= $_GET['id'] ?>&forumid=<?= $_GET['forumid'] ?>&deletetopic=<?= $array['topic_id'] ?>"
           onClick="return confirm('确定删除?');">删除</a></td>
        <td>
			<?= $array['topic_replies'] ?>
        </td>
        <td>
			<?= sql_topic_status( $array['topic_id'] ) ?>
        </td>
        <td>
            <a href="topicediter.php?action=edittopic&fid=<?= $_GET['forumid'] ?>&tid=<?= $array['topic_id'] ?>&back=<?= base64_encode( $_SERVER['REQUEST_URI'] ) ?>">编辑主题</a>
        </td>
        </tr>
		<?php
	}
	echo '</table>';
}


//目前位置:

function locationhead() {
	//主题页面
	echo '<hr />';
	if ( $_SERVER['PHP_SELF'] == "/bbs_0/topic.php" ) {
		echo '<a href="forum.php">论坛首页</a>';
		if ( isset( $_GET['topicid'] ) ) {
			$topicid = $_GET['topicid'];
			$forums  = sql_topicid_forums( $topicid );
			$areas   = sql_forumid_areas( $forums['forum_id'] );
			if ( $areas ) {
				//位于论坛区：
				echo '>' . '<a href="forum.php?areaid=' . $areas['area_id'] . '">' . $areas['area_title'] . '</a>';
				//位于板块：
				echo '>' . '<a href="forums.php?forumid=' . $forums['forum_id'] . '&p=1">' . $forums['forum_name'] . '</a>';
				//自身链接：
				$gettopicid = $_GET['topicid'];
				$topics     = sql_topicid_topics( $gettopicid );
				echo '>' . '<a href="topic.php?topicid=' . $gettopicid . '&p=1">' . $topics['topic_title'] . '</a>';
			} else {
				echo '出错了！请返回';
				exit();
			}
		}
	}
	if ( $_SERVER['PHP_SELF'] == "/bbs_0/forum.php" ) {
		echo '<a href="forum.php">论坛首页</a>';
		if ( isset( $_GET['areaid'] ) ) {
			$areaid = $_GET['areaid'];
			//位于论坛区
			$areas = sql_areaid_areas( $areaid );
			if ( $areas ) {
				echo '>' . '<a href="forum.php?areaid=' . $areaid . '">' . $areas['area_title'] . '</a>';
			} else {
				echo '出错了！请返回';
				exit();
			}
		}
	}
	if ( $_SERVER['PHP_SELF'] == "/bbs_0/forums.php" ) {
		echo '<a href="forum.php">论坛首页</a>';
		if ( isset( $_GET['forumid'] ) ) {
			$forumid   = $_GET['forumid'];
			$areas     = sql_forumid_areas( $forumid );
			$areaid    = $areas['area_id'];
			$areatitle = $areas['area_title'];
			if ( $areaid ) {
				if ( $areatitle ) {
					echo '>' . '<a href="forum.php?areaid=' . $areaid . '">' . $areatitle . '</a>';
					$forums = sql_forumid_forums( $forumid );
					echo '>' . '<a href="forums.php?forumid=' . $forumid . '&p=1">' . $forums['forum_name'] . '</a>';
				} else {
					echo '出错了！请返回';
					exit();
				}
			} else {
				echo '出错了！请返回';
				exit();
			}
		}
	}
	if ( $_SERVER['PHP_SELF'] == "/bbs_0/home.php" ) {
		//位于家

//用户是否存在：
		$issetusername = sql_searchName_login_uid_name( $_GET['uid'] );
		if ( $issetusername == null ) {
			echo "<a href='javascript:history.go(-1)'>返回上一步</a>";
			exit( '抱歉，您指定的用户空间不存在' );
		}
		if ( isset( $_GET['uid'] ) ) {
			$uid         = $_GET['uid'];
			$setuser_all = sql_search_uid_all( $uid );
			if ( $setuser_all ) {
				echo $uid;
				if ( isset( $_GET['mod'] ) ) {
					if ( $_GET['mod'] == "space" ) {
						echo '>' . '<a href="home.php?mod=space&uid=' . $uid . '">' . $setuser_all['user_username'] . '</a>';
						echo '>个人资料';
					}
				}
			} else {
				echo '出错了！请返回';
				exit();
			}
		}
	}
	if ( $_SERVER['PHP_SELF'] == "/bbs_0/admin.php" ) {
		echo '<a href = "admin.php">管理员面板</a>';
		if ( isset( $_GET['type'] ) && $_GET['type'] == 'area' ) {
			if ( isset( $_GET['id'] ) ) {
				echo '><a href = "admin.php?type=area&id=' . $_GET['id'] . '">论坛ID：' . $_GET['id'] . '</a>';
				if ( isset( $_GET['forumid'] ) ) {
					echo '><a href = "admin.php?type=area&id=' . $_GET['id'] . '&forumid=' . $_GET['forumid'] . '">板块ID：' . $_GET['forumid'] . '</a>';
				}
			}
		}
		echo '<hr />';
	}
	if ( $_SERVER['PHP_SELF'] == "/bbs_0/topicediter.php" ) {
		echo '<a href="forum.php">论坛首页</a>';
		if ( isset( $_GET['fid'] ) ) {
			$forumid = $_GET['fid'];
			$areas   = sql_forumid_areas( $forumid );
			if ( $areas ) {
				$areaid    = $areas['area_id'];
				$areatitle = $areas['area_title'];
				echo '>' . '<a href="forum.php?areaid=' . $areaid . '">' . $areatitle . '</a>';
				$forums = sql_forumid_forums( $forumid );
				echo '>' . '<a href="forums.php?forumid=' . $forumid . '&p=1">' . $forums['forum_name'] . '</a>';
			} else {
				echo '出错了！请返回';
				exit();
			}
		}
		echo '>';
		echo '<a href = "' . $_SERVER['REQUEST_URI'] . '">发表帖子</a>';
		echo '<hr />';
	}
}

//floor楼层
function ffloor( $floor ) {
	switch ( $floor ) {
		case '2':
			return '<span style="color:#7BCE3F">沙发</span>';
		case '3':
			return '<span style="color:#0066FF">藤椅</span>';
		case '4':
			return '<span style="color:#00ffff">板凳</span>';
		case '5':
			return '<span style="color:#E0E0E0">报纸</span>';
		case '6':
			return '<span style="color:#CC3300">地板</span>';
		default:
			return $floor . '#';
	}
}

//搜索框
function searchSubmit() {
	global $searchContent;

	?>
    <form action="search.php" method="get">
        <input type="text" id="centerid" name="content" placeholder="搜索关键字" value="<?= $searchContent ?>"/>
        <select name="tag">
			<?php
			if ( isset( $_GET['tag'] ) ) {
				if ( $_GET['tag'] == 2 ) {
					print '
            <option value="1"> 帖子</option>
            <option value="2" selected="selected"> 用户</option>
                    ';
				} else {
					print '
            <option value="1" selected="selected"> 帖子</option>
            <option value="2""> 用户</option>
                    ';
				}
			} else {
				print '
            <option value="1" selected="selected"> 帖子</option>
            <option value="2"> 用户</option>
                    ';
			}
			?>
        </select>
        <input type="submit" onclick="
        if (document.getElementById('centerid').value == '') {
            alert('请输入关键字。');
            document.getElementById('key_word').focus();
        }
" value="搜索">
    </form>
	<?php
}

//列出用户主题
function list_topics() {
	?>

    <table border="1" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <th width="30%">
                主题
            </th>
            <th width="15%">
                板块
            </th>
            <th width="10%">
                回复/查看
            </th>
            <th width="15%">
                发帖时间
            </th>
            <th width="10%">
                状态
            </th>
        </tr>
		<?php
		$topics = sql_poster_topics( $_GET['uid'] );
		while ( ( $topics_array = mysqli_fetch_array( $topics ) ) != null ) {
			$count_result = sql_topic_page( $topics_array['topic_id'] );
			$count_array  = mysqli_fetch_array( $count_result );
			echo '<tr>';
			echo '<td>';
			echo '<a href="topic.php?topicid=' . $topics_array['topic_id'] . '&p=1">' . $topics_array['topic_title'] . '</a>';
			echo '</td>';
			echo '<td>';
			//根据板块编号查板块名
			$forums     = sql_forumid_forums( $topics_array['topic_forumid'] );
			$forum_name = $forums['forum_name'];
			echo '<a href="forums.php?forumid=' . $forums['forum_id'] . '&p=1">' . $forum_name . '</a>';
			echo '</td>';
			echo '<td>' . ( $count_array['COUNT(*)'] - 1 ) . '</td>';
			echo '<td>';
			echo date( 'Y-m-d', $topics_array['topic_createtime'] );
			echo '</td>';
			?>
            <td>
				<?= sql_topic_status_user( $topics_array['topic_id'] ) ?>
            </td>
			<?php
			echo '</tr>';
		}
		if ( isset( $_SESSION['uid'] ) && $_SESSION['uid'] == $_GET['uid'] ) {
			sql_delNotify( $_GET['uid'] );
		}
		?>
    </table>
	<?php
}

//列出用户回复
function list_reply() {
	?>

    <table border="1" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <th width="30%">
                帖子
            </th>
            <th width="15%">
                板块
            </th>
            <th width="10%">
                回复/查看
            </th>
            <th width="15%">
                回帖时间
            </th>
        </tr>
		<?php
		$posts = sql_authuid_posts( $_GET['uid'] );
		while ( ( $posts_array = mysqli_fetch_array( $posts ) ) != null ) {
			echo '<tr>';
			echo '<td>';
			//帖子标题
			$topics = sql_topicid_topics( $posts_array['post_topicid'] );
			echo '<a href="topic.php?topicid=' . $posts_array['post_topicid'] . '&p=1">' . $topics['topic_title'] . '</a><br />';
			//帖子回复
			echo '回复内容：<a href="topic.php?topicid=' . $posts_array['post_topicid'] . '&p=1">' . $posts_array['post_content'] . '</a>';
			echo '</td>';
			echo '<td>';
			//根据帖子id中的帖子板块id查板块名

			$topics     = sql_topicid_topics( $posts_array['post_topicid'] );
			$forums     = sql_forumid_forums( $topics['topic_forumid'] );
			$forum_name = $forums['forum_name'];
			echo '<a href="forums.php?forumid=' . $forums['forum_id'] . '&p=1">' . $forum_name . '</a>';
			echo '</td>';
			echo '<td></td>';
			echo '<td>';
			echo date( 'Y-m-d', $posts_array['post_createtime'] );
			echo '</td>';
			echo '</tr>';
		}
		?>
    </table>
	<?php
}

//管理员管理用户：
function adminUser() {
	//用户uid搜索框：

	//用户列表：

	//点击用户进入用户面板：
	//可修改头像，账号，密码：
	//增加用户
	//删除用户，删除时先删除用户的回帖，再删除用户的帖子，最后删除用户
	if ( ( ! isset( $_GET['type'] ) ) || ( $_GET['type'] == 'users' ) ) {
		if ( isset( $_GET['searchUsers'] ) ) {
			$searchUserText = $_GET['searchUsers'];
		} else {
			$searchUserText = '';
		}
		?>
        <hr/>
        <h4 id="userSet">用户管理区：</h4>
        <form action="admin.php" method="get">
            <input type="text" name="searchUsers" value="<?= $searchUserText ?>"/>
            <input type="submit" value="搜索用户"/><a href="signin.php">注册新用户</a>
        </form>
        <p/>
        <table border="1" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <th width="5%">
                    序号
                </th>
                <th width="15%">
                    用户名
                </th>
                <th width="5%">
                    用户组
                </th>
                <th width="10%">
                    uid
                </th>
                <th width="20%">
                    在线状态
                </th>
            </tr>
			<?php
			if ( isset( $_GET['searchUsers'] ) ) {
				$user_name = htmlspecialchars_decode( addslashes( $_GET['searchUsers'] ) );
			} else {
				$user_name = '';
			}
			//翻页
			if ( isset( $_GET['p'] ) ) {
				$p = $_GET['p'];
			} else {
				$p = 1;
			}
			$users_query = sql_list_users( $user_name, ( $p - 1 ) * 10, 10 );
			$count       = $users_query[1];
			$pagenum     = ceil( $count / 10 );
			if ( $p > 1 ) {
				echo '<a href="admin.php?searchUsers=' . $user_name . '&p=' . ( $p - 1 ) . '#userSet"><<上一页</a>&nbsp;&nbsp;';
			}
			echo '共 ', $count, ' 人';
			if ( $pagenum > 1 ) {
				for ( $i = 1; $i <= $pagenum; $i ++ ) {
					if ( $i == $p ) {
						echo '&nbsp;[', $i, ']';
					} else {
						echo '&nbsp;<a href="admin.php?searchUsers=' . $user_name . '&p=' . $i . '#userSet">' . $i . '</a>';
					}
				}
			}
			if ( $p < $pagenum ) {
				echo '&nbsp;&nbsp;<a href="admin.php?searchUsers=' . $user_name . '&p=' . ( $p + 1 ) . '#userSet">下一页>></a>';
			}
			$i = ( $p - 1 ) * 10 + 1;
			while ( ( $users_array = mysqli_fetch_array( $users_query[0] ) ) ) {
				echo '<tr>';
				echo '<td>' . $i . '</td>';
				echo '<td>';
				echo '<a href="home.php?mod=space&uid=' . $users_array['user_uid'] . '">' . $users_array['user_username'] . '</a>';
				echo '</td>';
				echo '<td>';
				echo sql_search_rank_rankname( $users_array['user_rank'] );
				echo '</td>';
				echo '<td>';
				echo $users_array['user_uid'];
				echo '</td>';
				echo '<td>';
				if ( $users_array['user_login'] == 0 ) {
					echo '<span style="color: #FF0000">离线</span>';
				} else {
					echo '<span style="color: #009933">在线</span>';
				}
				if ( $users_array['user_logintime'] > time() ) {
					echo " <span style='color: #FF0000'>封禁至：" . date( "Y-m-d h:i:s", $users_array['user_logintime'] ) . "</span>";
					echo ' <input type="button" onclick="ajaxpost_loginout(' . $users_array['user_uid'] . ', 0)" value="还原"/>';
				} else {
					echo ' <input type="button" onclick="ajaxpost_loginout(' . $users_array['user_uid'] . ', 1)" value="封禁"/>';
				}
				echo '</td>';
				echo '</tr>';
				$i ++;
			}
			?>
        </table>
		<?php
	}
}

//回帖通知
function reply_notify( $uid ) {
	$userAll = sql_search_uid_all( $uid );
	if ( $userAll['user_notify'] == 1 ) {
		echo ' <a href="home.php?mod=space&uid=' . $uid . '&do=thread">有新消息！</a>';
	} else {
		echo ' 没有新消息';
	}
}

function notify() {
	echo '<hr />';
	echo '回帖：<br />';

	exit();
}

//关键字屏蔽
function adminKey() {
	echo '<hr />';
	echo '<h5>关键字屏蔽</h5>';
	?>
    <table border="1" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <th>
                关键字
            </th>
            <th>
                修改为
            </th>
            <th>
                删除
            </th>
        </tr>
		<?php
		$query = sql_key_query();
		while ( ( $array = mysqli_fetch_array( $query ) ) != false ) {
			echo '<tr>';
			echo '<td>';
			echo htmlspecialchars( $array['key_name'] );
			echo '</td>';
			echo '<td>';
			echo htmlspecialchars( $array['key_change'] );
			echo '</td>';
			echo '<td>';
			$array_id = $array['id'];
			echo '<input type="checkbox" onchange="ajaxpost_del_key(
            ' . $array_id . ')"';
			echo '</td>';
			echo '</tr>';
		}

		?>
    </table>
    <input type="text" id="key_word" placeholder="关键字"/><input type="text" id="change_word" placeholder="修改为"/><input
            type="button" onclick="ajaxpost_add_key()" value="增加一行"/>
	<?php
}

//验证码
function verificationCode(){
	$width  = 210;
	$height = 50;
	$image  = imagecreatetruecolor( $width, $height );

	$string = join( "", array_merge( range( 0, 9 ), range( "a", "z" ), range( "A", "Z" ) ) );
//echo $string;

	function randColor( $image ) {
		return imagecolorallocate( $image, mt_rand( 0, 255 ), mt_rand( 0, 255 ), mt_rand( 0, 255 ) );
	}

	$white = imagecolorallocate( $image, 255, 255, 255 );

	imagefilledrectangle( $image, 0, 0, 500, 500, $white );

	$fonts_array = array( 'fonts/STHUPO.TTF', 'fonts/hzgb2.ttf', 'fonts/simhei.ttf', 'fonts/STFANGSO.TTF' );

	$outText = "";

	for ( $i = 0; $i < 4; $i ++ ) {
		$front_rand  = $fonts_array[ mt_rand( 0, 3 ) ];
		$text = str_shuffle( $string )[0];
		imagettftext( $image,30, mt_rand( - 45, 45 ), ( $i + 1 ) * 35, 35, randColor( $image ), $front_rand, $text);
		$outText .= $text;
	}
	$_SESSION['verify'] = $outText;

	for ($i = 0; $i < 100; $i ++){
		imagesetpixel($image, mt_rand(0,$width), mt_rand(0, $height), randColor($image));
	}
	for ($i = 0; $i < 5; $i ++){
		imageline($image, mt_rand(0,$width), mt_rand(0, $height), mt_rand(0,$width), mt_rand(0, $height), randColor($image));
	}
	for ($i = 0;$i < 10; $i ++){
		imagearc($image, mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $width/(mt_rand(1, 10))), mt_rand(0, $width/(mt_rand(1, 10))), mt_rand(0, 360), mt_rand(0, 360), randColor($image));
	}
//echo $outText;
//imagettftext($image, 50, 0, 60, 70, randColor($image), $front_rand, '*(oo)*');
//for ($i = 0; $i < 3; $i++){
//	imagettftext($image, 50, mt_rand(-45,45), 50 * $i, 150, $rand_color, $fonts_array[mt_rand(0,3)], $no1);
//}

	mb_internal_encoding( "UTF-8" );
	header( 'Content-Type: image/png' );
	imagepng( $image );
//imagepng( $image, 'png/test4,png' );
	imagedestroy( $image );
}